﻿namespace FrontEnd
{
	using System.Web;
	using System.Web.Mvc;
	using System.Web.Routing;
	using Microsoft.Practices.Unity;
	using Application;
	using Core;

    public class FronEndApplication : HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

			routes.MapRoute(
				"Default",
				"{Controller}/{action}/{id}",                           // URL with parameters
				new { Controller = "Home", Action = "Index", Id = "" }  // Parameter defaults
			);
        }

		private static void RegisterDependencies()
		{
			// Setup container
			IUnityContainer container = new UnityContainer();

			CoreRegistration.RegisterWithIn(container);
			ApplicationRegistration.RegisterWithIn(container);
			
			UnityControllerFactory controllerFactory
				= new UnityControllerFactory(container);

			ControllerBuilder.Current.SetControllerFactory(controllerFactory);
		}

        protected void Application_Start()
        {
        	RegisterDependencies();
        	RegisterRoutes(RouteTable.Routes);
        }    	
    }
}